/********************************************************************************
 * @file     define.h
 * @author   user
 * @version  v0
 * @date     March 2020
 * @brief    This file contains all the functions prototypes for the SDADC firmware
 *           library

 * Copyright (C) 2020 Hangzhou SDIC Microelectronics Co., Ltd
**********************************************************************************/


#ifndef __Define_H__
#define __Define_H__
#include "SD93F115B_buz.h"
#include "SD93F115B_dbgmcu.h"
#include "SD93F115B_exti.h"
#include "SD93F115B_flash.h"
#include "SD93F115B_gpio.h"
#include "SD93F115B_i2c.h"
#include "SD93F115B_it.h"
#include "SD93F115B_iwdg.h"
#include "SD93F115B_lcd.h"
#include "SD93F115B_pwm.h"
#include "SD93F115B_pwr.h"
#include "SD93F115B_rcc.h"
#include "SD93F115B_rtc.h"
#include "SD93F115B_saradc.h"
#include "SD93F115B_sdadc.h"
#include "SD93F115B_op.h"
#include "SD93F115B_spi.h"
#include "SD93F115B_systick.h"
#include "SD93F115B_tim.h"
#include "SD93F115B_uart.h"
#include "SD93F115B_vic.h"
#include "SD93F115B_wwdg.h"
#include "BIA.h"
//=====================================user===============================================
/*
#include "disp.h"
#include "power.h"
#include "clk.h"
#include "gpio.h"
#include "time.h"
#include "uart.h"
#include "spk.h"
#include "flash.h"
#include "adc.h"
#include "algo.h"
#include "bp.h"
#include "func.h"
#include "op.h"
#include "pwm.h"

*/
//#include "spk.h"
//#include "spk.h"
//#include "spk.h"
//#include "spk.h"









/********************************/
#include "BIA.h"


typedef	struct
{
	uint8_t rec		:1;
	uint8_t tran	:1;
	uint8_t recOver :1;
	uint8_t Receive_END :1;
	uint8_t NoReceive :1;
	uint8_t rctimeOver :1;
	uint8_t sdtimeOver :1;
	uint8_t NO_ACK_CS :1;

	uint8_t Disallflag :1;
	uint8_t adcupdata:1;

}stateFlag_typedef;

extern stateFlag_typedef stateFlag;

#define		P40_0		        (GPIO4->ODR &= ~(1UL<<0))	    //P40=0
#define		P40_1		        (GPIO4->ODR |= (1UL<<0))		//P40=1

/*******************funcation********************/
void LCD_Initialization(void);

void Init(void);
void PWR_Initialization(void);
void VIC_Initialization(void);

void EXINT_Initialization(void);
void RTC_Initialization(void);
void IWDG_Initialization(void);
void WWDG_Initialization(void);

void UART_Initialization(void);

void GPIO_Initialization(void);
void TM_Initialization(void);



//============================BP DIFINE========================================

#define u8  uint8_t
#define u16 uint16_t
#define u32 uint32_t


#define uint8  uint8_t
#define uint16 uint16_t
#define uint32 uint32_t




typedef volatile union byte_bit
	{
		struct
		{
			uint8 bit0:1;
			uint8  bit1:1;
			uint8  bit2:1;
			uint8  bit3:1;
			uint8  bit4:1;
			uint8  bit5:1;
			uint8  bit6:1;
			uint8  bit7:1;
		}bt;
		uint8    b;
	}byte_bit;
typedef volatile union word_data
{
	uint16 	w;
	uint8 	b[2];
}word_data;
typedef volatile union dword_data
{
	uint32    l;
	uint16 	w[2];
	uint8 	b[4];
}dword_data;

extern volatile union byte_bit					MeasureStateFlag;
#define   SamplePressure		MeasureStateFlag.bt.bit0
#define   SampleSignal  		MeasureStateFlag.bt.bit1

extern volatile union byte_bit					STATEFlag1;
#define   First30mmHg  			STATEFlag1.bt.bit0
#define   MemoryMode				STATEFlag1.bt.bit1
#define   RePump   					STATEFlag1.bt.bit2
#define   GetLeakagePresureFlag	STATEFlag1.bt.bit3
#define   MemoryFull				STATEFlag1.bt.bit4
#define   FirstDeflate  		STATEFlag1.bt.bit5

extern volatile union byte_bit					OneShotFlag;
#define   OneShot 					OneShotFlag.bt.bit0
#define   OneShotDC					OneShotFlag.bt.bit1
#define   KeyIn 						OneShotFlag.bt.bit2
#define   SecondFlag				OneShotFlag.bt.bit3
#define   OneShotPump				OneShotFlag.bt.bit4
#define   OneShotValve			OneShotFlag.bt.bit5
#define   OneShotRX					OneShotFlag.bt.bit6

extern volatile union byte_bit					initstates;
#define   SmallSignalOn 		initstates.bt.bit0
#define   NormalSignal  		initstates.bt.bit1
#define   LargeSignalOn 		initstates.bt.bit2


extern volatile union byte_bit					AlgoStateFlag;
#define   HeartSign			AlgoStateFlag.bt.bit0
#define   NormalResultCode	AlgoStateFlag.bt.bit1
#define   RepumpCheckFlag		AlgoStateFlag.bt.bit2
//#define   SX4      				AlgoStateFlag.bt.bit3
#define   PeakFlag 					AlgoStateFlag.bt.bit4
#define   FindFlag					AlgoStateFlag.bt.bit5
#define   Thresnum1					AlgoStateFlag.bt.bit6
#define   Thresnum2					AlgoStateFlag.bt.bit7

extern volatile union byte_bit					AlgorithmFlag;
#define   AlgoFindMAPFlag		AlgorithmFlag.bt.bit0
#define   AlgoSysOkFlag  		AlgorithmFlag.bt.bit1
#define   AlgoDiaOkFlag  		AlgorithmFlag.bt.bit2
#define   AlgoMAPOkFlag  		AlgorithmFlag.bt.bit3
#define   AlgoOnePFlag   		AlgorithmFlag.bt.bit4
#define   AlgoFirstPFlag 		AlgorithmFlag.bt.bit5
#define   AlgoMaxPFlag   		AlgorithmFlag.bt.bit6
#define   AlgoExchFlag			AlgorithmFlag.bt.bit7

extern volatile union byte_bit					SysStateFlag;
#define   IsPowerOn					SysStateFlag.bt.bit0
#define   IsAlgoEnd  				SysStateFlag.bt.bit1
#define   IsCalibrate				SysStateFlag.bt.bit2
#define   IsAlgorithm				SysStateFlag.bt.bit3
#define   IsMinute					SysStateFlag.bt.bit4
#define   IsShowResult			SysStateFlag.bt.bit5
#define   IsShowPressure		SysStateFlag.bt.bit6
#define   IsPump						SysStateFlag.bt.bit7

extern volatile union byte_bit					SysStateFlag2;
#define   BTFlag 						SysStateFlag2.bt.bit0
#define   IsCALMode					SysStateFlag2.bt.bit1
#define	  EepromNoSet				SysStateFlag2.bt.bit2
#define	  ReadEepromError		SysStateFlag2.bt.bit3
#define	  FirstPulse				SysStateFlag2.bt.bit4
#define	  PADFlag						SysStateFlag2.bt.bit5
#define	  VoiceStop					SysStateFlag2.bt.bit6

//#define	  IsRTC1minMode				SysStateFlag2.bt.bit7		//202305


extern volatile union byte_bit					SystemSetFlag;
#define	  PADEnable					SystemSetFlag.bt.bit0
#define	  TwoUser						SystemSetFlag.bt.bit1
#define   RCSensorType  		SystemSetFlag.bt.bit2
#define   LinearValveFlag  	SystemSetFlag.bt.bit3
#define	  PowerType					SystemSetFlag.bt.bit4
#define   AMPMLCD   				SystemSetFlag.bt.bit5
#define   NoTimer 					SystemSetFlag.bt.bit6
#define	  UparmWWFlag				SystemSetFlag.bt.bit7

extern volatile union byte_bit					SystemSetFlag2;
#define   InfDefFlag 				SystemSetFlag2.bt.bit0
#define   UnitSetEnable     SystemSetFlag2.bt.bit1
#define	  AverageType				SystemSetFlag2.bt.bit2
#define	  BLFlag						SystemSetFlag2.bt.bit3
#define	  VoiceSetEnable		SystemSetFlag2.bt.bit4
#define	  EndVoice					SystemSetFlag2.bt.bit5
#define	  BTIconEnable			SystemSetFlag2.bt.bit6
#define	  BTEnable					SystemSetFlag2.bt.bit7

extern volatile union byte_bit					SystemSetFlag3;
#define	  UnitIcon					SystemSetFlag3.bt.bit0
#define		CuffDetect					SystemSetFlag3.bt.bit1
#define		AlarmClock				SystemSetFlag3.bt.bit2
#define	  E2Mode						SystemSetFlag3.bt.bit3
#define		SetMode2					SystemSetFlag3.bt.bit4
#define		LCDType						SystemSetFlag3.bt.bit5
#define		NoTimeSet					SystemSetFlag3.bt.bit6
#define		MoveDetect				SystemSetFlag3.bt.bit7

extern  uint8 VoiceFlag;	//多语种

extern volatile union byte_bit					SystemSetFlag4;
#define	  BZEnable				SystemSetFlag4.bt.bit0
#define	  ShowMean				SystemSetFlag4.bt.bit1
#define		AUSMode					SystemSetFlag4.bt.bit2
#define		LCDType2				SystemSetFlag4.bt.bit3
#define		StartBZ					SystemSetFlag4.bt.bit4
#define		LCD80Y					SystemSetFlag4.bt.bit5
#define		DPIconDisable		SystemSetFlag4.bt.bit6
#define		UserSetEnable		SystemSetFlag4.bt.bit7

extern volatile union byte_bit					SystemSetFlag5;
#define	  SendRomFlag				SystemSetFlag5.bt.bit0
#define		MemoryChangeFlag	SystemSetFlag5.bt.bit1

extern volatile union byte_bit					SystemSetFlag6;
#define	  SendOKFlag				SystemSetFlag6.bt.bit0
#define	  ThreeKeyFlag			SystemSetFlag6.bt.bit1
#define	  SendMemoryFlag		SystemSetFlag6.bt.bit2
#define		ADOKFlag					SystemSetFlag6.bt.bit3
#define		functionOKFlag		SystemSetFlag6.bt.bit4
#define		AlarmFlag					SystemSetFlag6.bt.bit5
#define		AutoTestFlag			SystemSetFlag6.bt.bit6
#define		VoiceSetFlag			SystemSetFlag6.bt.bit7

extern volatile union byte_bit					UserSetFlag;
#define	  mmHgkPaFlag				UserSetFlag.bt.bit0
#define	  VoiceEnable				UserSetFlag.bt.bit1
#define	  UserA							UserSetFlag.bt.bit2

extern volatile union byte_bit					KeyFlag;
#define		KeyError					KeyFlag.bt.bit0
#define	  Key1							KeyFlag.bt.bit1
#define		Key2							KeyFlag.bt.bit2
#define		Key3							KeyFlag.bt.bit3
#define		KEY_TIME					KeyFlag.bt.bit4
#define		KEY_POWER					KeyFlag.bt.bit5//20220420
#define		KEY_MEMORYUP					KeyFlag.bt.bit6
#define keylimit 10

extern volatile union byte_bit					MemorySetFlag;
#define HaveMemoryFirst			MemorySetFlag.bt.bit0
#define HaveMemoryAvg				MemorySetFlag.bt.bit1
#define HaveMemoryAvg1			MemorySetFlag.bt.bit2
#define MemoryClredFlag			MemorySetFlag.bt.bit3
#define SetPressureOKFlag   MemorySetFlag.bt.bit4
#define CalScaleFirstFlag   MemorySetFlag.bt.bit5



extern volatile  union byte_bit					TimeBase;
#define   T160Hz						TimeBase.bt.bit0
#define   T80Hz							TimeBase.bt.bit1
#define   T40Hz							TimeBase.bt.bit2
#define   T20Hz							TimeBase.bt.bit3
#define   T10Hz							TimeBase.bt.bit4

extern volatile union byte_bit					WatchTime;
#define   T625ms						WatchTime.bt.bit0
#define   T125ms 						WatchTime.bt.bit1
#define   T250ms 						WatchTime.bt.bit2
#define   T500ms 						WatchTime.bt.bit3
#define   T1s	  						WatchTime.bt.bit4
#define   T2s	  						WatchTime.bt.bit5
#define   T4s   						WatchTime.bt.bit6
#define   T8s	  						WatchTime.bt.bit7

extern volatile union byte_bit					Year;
#define   YEAR0							Year.bt.bit0
#define   YEAR1							Year.bt.bit1

extern volatile union	word_data				AutoOffTime2 ;
#define	AutoOffTimew 				AutoOffTime2.w
#define	AutoOffTime2b				AutoOffTime2.b[1]
#define	AutoOffTime1b				AutoOffTime2.b[0]
//202305
#define AutoOffTimew_20_MS_COUNT 1  //AutoOffTimew corresponding timing value
#define AutoOffTimew_100_MS_COUNT (AutoOffTimew_20_MS_COUNT * 5)
#define AutoOffTimew_1_S_COUNT (AutoOffTimew_100_MS_COUNT * 10)
extern volatile union	word_data				PressCount ;
#define	PressCountw 				PressCount.w
#define	PressCount2b				PressCount.b[1]
#define	PressCount1b				PressCount.b[0]

extern volatile union	word_data				SensorCount;
#define	 SensorCountw 			SensorCount.w
#define	 SensorCount2b			SensorCount.b[1]
#define	 SensorCount1b			SensorCount.b[0]

extern volatile union	word_data				ADCount ;
#define	 ADCountw 					ADCount.w
#define	 ADCount2b					ADCount.b[1]
#define	 ADCount1b					ADCount.b[0]

extern volatile union	word_data				PressuremmHg;
#define	 PressuremmHgw 			PressuremmHg.w
#define	 PressuremmHg2b			PressuremmHg.b[1]
#define	 PressuremmHg1b			PressuremmHg.b[0]
extern volatile union	word_data				OscilloSignal  ;
#define	 OscilloSignalw  		OscilloSignal.w
#define	 OscilloSignal02b		OscilloSignal.b[1]
#define	 OscilloSignal01b		OscilloSignal.b[0]

extern volatile union	dword_data			Math;
#define	  Mathhw 						Math.w[1]
#define	  Math04b						Math.b[3]
#define	  Math03b						Math.b[2]
#define	  Mathlw						Math.w[0]
#define	  Math02b						Math.b[1]
#define	  Math01b						Math.b[0]

extern volatile union	word_data				AA1w;
#define	AA1 								AA1w.w
#define	AA12b								AA1w.b[1]
#define	AA11b								AA1w.b[0]
extern volatile union	word_data				B1w;
#define	B1 									B1w.w
#define	B12b								B1w.b[1]
#define	B11b								B1w.b[0]
extern volatile union	word_data				C1w;
#define	C1 									C1w.w
#define	C12b								C1w.b[1]
#define	C11b								C1w.b[0]

extern volatile union	word_data				ZeroCount;
#define	 ZeroCountw 				ZeroCount.w
#define	 ZeroCount2b				ZeroCount.b[1]
#define	 ZeroCount1b				ZeroCount.b[0]

extern volatile union	word_data				SystolicValue;
#define	 SystolicValuew 		SystolicValue.w
#define	 SystolicValue2b		SystolicValue.b[1]
#define	 SystolicValue1b		SystolicValue.b[0]

extern volatile union	dword_data			TemplateValue;
#define	 TemplateValueLong	TemplateValue.l
#define	 TemplateValuehw 		TemplateValue.w[1]
#define	 TemplateValue04b		TemplateValue.b[3]
#define	 TemplateValue03b		TemplateValue.b[2]
#define	 TemplateValuelw 		TemplateValue.w[0]
#define	 TemplateValue02b		TemplateValue.b[1]
#define	 TemplateValue01b		TemplateValue.b[0]


extern volatile union	word_data				Xx;
#define	  Xxw 							Xx.w
#define	  Xx2b							Xx.b[1]
#define	  Xx1b							Xx.b[0]

extern volatile union	word_data				Dy;
#define	  Dyw 							Dy.w
#define	  Dy2b							Dy.b[1]
#define	  Dy1b							Dy.b[0]


extern volatile union byte_bit  KeyModeFlag;
#define	SetKeyFlag 		KeyModeFlag.bt.bit0
#define	MemoryKeyFlag	KeyModeFlag.bt.bit1
#define	PowerKeyFlag	KeyModeFlag.bt.bit2
















extern volatile union 	byte_bit				mtemp0c,mtemp1c;
extern volatile union 	byte_bit				IDbuffer;
extern volatile union 	byte_bit				ibuffer;
extern volatile union	word_data				PulseRam[63];
extern volatile union	word_data				PulsePressure[4];


#define Enable 								1
#define Disable 							0


#define CALPressureLimit				500					//20mmHg
#define	SYSMargin								16;					//16mmHg		//20121002
#define	DIAMargin								10;					//10mmHg
#define	TimeMargin							180;  			//3??

extern uint8 ModifyFlag;
extern uint8 AllTimeFlag;
extern uint16 AUTOOFFTIME;
//#define AUTOOFFTIME							0x23				// Auto off time 0x2328=3min
#define TWO											0x003f			// 1.5sec TWO
#define PUMPTIMEL								0x050a 			//0x02aa	PUMPTIME LONG 16 second
#define PUMPTIMES								0x01ae			//0x00aa	 PUMPTIME SHORT 4 second
#define PUMPTIMEP								30					// PUMPTIME Pressure
#define SoundDelayValue					1000

//#define YEARINIT								19				// 2016
#define MONTHINIT								1					// 1-1
#define DAYINIT 								1					// 1:00
#define HOURINIT								0
#define MINUTEINIT							0

#define VerYear									23
#define	VerMonth								8
#define	VerDay									14


#define RepumpOffset						0x28				// repump addition pressure value:40mmHg
#define	SpanValve								1						// sensor span

#define WHOSYS0									90				//202305
#define WHODIA0									60				//202305


#define WHOSYS1									120
#define WHODIA1									80
#define WHOSYS2									130
#define WHODIA2									85
#define WHOSYS3									140
#define WHODIA3									90
#define WHOSYS4									160
#define WHODIA4									100
#define WHOSYS5									180
#define WHODIA5									110




#define	 VALVE									0x10				// VALVE
#define  PUMP										0x20				// PUMP
#define  POWER									0x40				// POWER
#define  LBTVAL										0x80				// LBT

#define  VALVEOFF								0x10			// VALVE off
#define  PUMPOFF 								0x20			// PUMP off
#define  POWEROFF								0x40			// POWER off
#define  LBTOFF									0x80			// LBT off

#define  AA1UP										2865				//2980				//7513
#define  B1UP										2702				//2750
#define  C1UP										2412				//2350
#define  A1WW										2865				//2980
#define  B1WW										2702
#define  C1WW										2412

#define  A1UPR									12500
#define  A1WWR									10000





//#define debugon












#endif /* define_H */

/************************ (C) COPYRIGHT Hangzhou SDIC Microelectronics *****END OF FILE****/
